<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('username')->comment('用户名');
            $table->string('password')->comment('用户密码');
            $table->integer('employee_id')->unsigned()->comment('员工ID')->nullable();
            $table->foreign('employee_id')->references('id')->on('employees')->onDelete('set null');
            $table->char('status',1)->comment('账号状态 1:正常 2:禁止登陆')->default(1);
            $table->integer('picture')->comment('头像id')->nullable();
            $table->string('condition')->comment('个人签名;状态')->nullable();
            $table->timestamp('start_time')->comment('有效期-开始时间')->nullable();
            $table->timestamp('end_time')->comment('有效期-结束时间')->nullable();
            $table->string('remember_token',60)->unique()->nullable();
            $table->timestamp('last_login_time')->comment('最后登录时间')->nullable();
            $table->string('last_ip',32)->comment('最后登录IP')->nullable();
            $table->softDeletes();
            $table->timestamps();
            $table->unique(['username','deleted_at']);
        });

        //用户微信的信息
        Schema::create('weichat_users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->tinyInteger('subscribe')->comment('用户是否订阅该公众号标识，值为0时，代表此用户没有关注该公众号，拉取不到其余信息。');
            $table->string('openid')->comment('用户的标识，对当前公众号唯一')->unique();
            $table->string('nickname')->comment('用户的昵称');
            $table->tinyInteger('sex')->comment('用户的性别，值为1时是男性，值为2时是女性，值为0时是未知');
            $table->string('city')->comment('部用户所在城市');
            $table->string('country')->comment('用户所在国家');
            $table->string('province')->comment('用户说明');
            $table->string('headimgurl')->comment('用户头像url');
            $table->timestamp('subscribe_time')->comment('用户关注时间，为时间戳。如果用户曾多次关注，则取最后关注时间')->nullable();
            $table->string('equipment')->nullable()->comment('绑定设备号');
            $table->string('card')->nullable()->comment('绑定卡号卡号');
            $table->float('accumulation_point')->default(0)->comment('累计积分');
            $table->float('point')->default(0)->comment('可用积分');
            $table->unsignedTinyInteger('level')->default(1)->comment('用户等级');
            $table->softDeletes();
            $table->timestamps();
        });
        //微信卡号绑定
        Schema::create('weichat_card', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('card')->comment('绑定卡号')->unique();
            $table->string('pwd')->comment('卡号密码');
            $table->boolean('is_use')->comment('卡号是否失效')->default(true);
            $table->softDeletes();
            $table->timestamps();
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('weichat_card');
        Schema::dropIfExists('weichat_users');
        Schema::dropIfExists('users');
    }
}
